package net.csdn.business.mirror.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.common.service.SuperServiceImpl;
import net.csdn.business.mirror.entity.bean.ProjectGithubData;
import net.csdn.business.mirror.mapper.ProjectGithubDataMapper;
import net.csdn.business.mirror.service.ProjectGithubDataService;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Slf4j
@Service
public class ProjectGithubDataServiceImpl extends SuperServiceImpl<ProjectGithubDataMapper, ProjectGithubData> implements ProjectGithubDataService {

    @Override
    public void saveOrUpdateData(ProjectGithubData data) {
        QueryWrapper<ProjectGithubData> query = new QueryWrapper<>();
        query.lambda().eq(ProjectGithubData::getMirrorId, data.getMirrorId());
        ProjectGithubData originData = baseMapper.selectOne(query);
        if (Objects.isNull(originData)) {
            baseMapper.insert(data);
            return;
        }
        data.setId(originData.getId());
        baseMapper.updateById(data);
    }
}
